package com.zuoshenge.main.controller;

import com.zuoshenge.bean.JsonResult;
import com.zuoshenge.main.excel.importt.CourseExcelImport;
import com.zuoshenge.main.excel.importt.listener.CourseExcelImportListener;
import com.zuoshenge.main.service.CourseService;
import com.zuoshenge.tool.Base64Utils;
import com.zuoshenge.util.UploadFileToRemoteUtils;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import java.io.IOException;

@RequestMapping("/test")
@RestController
public class TestController {
//    @Value("${base64}")
    private String base64code;

    @Resource
    private CourseExcelImport courseExcelImport;
    @Resource
    private CourseService courseService;

    @PostMapping("/post-test")
    public void test() {
        System.out.println("post test ok");
    }

    @PostMapping("/file-upload")
    public void fileUpload() throws IOException {
        MultipartFile multipartFile = Base64Utils.convertBase64ToMultipart(base64code, "t2.png");
        JsonResult jsonResult = UploadFileToRemoteUtils.uploadFileToRemoteServer(multipartFile);
    }

    @PostMapping("/file-deleted")
    public void fileDeleted() throws IOException {
        UploadFileToRemoteUtils.deleteFileToRemoteServer(null);
    }

    @GetMapping("/test-course-excel-import")
    public void testCourseExcelImport() {
        courseExcelImport.doImport("C:/Users/caojiarong/Desktop/课程列表 (35).xlsx",1,new CourseExcelImportListener(courseService));
    }
}
